home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / etc_-_Configuration_Files / PCMCIA / NETWORK < prev    next >
Text File  |  1999-09-17  |  5KB  |  195 lines

  1. #! /bin/sh
  2. #
  3. # network 1.49 1999/01/29 09:20:46 (David Hinds)
  4. #
  5. # Initialize or shutdown a PCMCIA ethernet adapter
  6. #
  7. # This script should be invoked with two arguments.  The first is the
  8. # action to be taken, either "start", "stop", or "restart".  The
  9. # second is the network interface name.
  10. #
  11. # The script passes an extended device address to 'network.opts' in
  12. # the ADDRESS variable, to retrieve device-specific configuration
  13. # options.  The address format is "scheme,socket,instance,hwaddr"
  14. # where "scheme" is the current PCMCIA device configuration scheme,
  15. # "socket" is the socket number, "instance" is used to number multiple
  16. # interfaces in a single socket, and "hwaddr" is the card's hardware
  17. # ethernet address.
  18. #
  19.  
  20. if [ -r ./shared ] ; then . ./shared ; else . /etc/pcmcia/shared ; fi
  21.  
  22. # Get device attributes
  23. get_info $DEVICE
  24. HWADDR=`/sbin/ifconfig $DEVICE | sed -n -e 's/.*addr \([^ ]*\)/\1/p'`
  25.  
  26. # Load site-specific settings
  27. ADDRESS="$SCHEME,$SOCKET,$INSTANCE,$HWADDR"
  28. start_fn () { return; }
  29. stop_fn () { return; }
  30. . $0.opts
  31.  
  32. RESOLV=/etc/resolv.conf
  33.  
  34. case "$ACTION" in
  35.  
  36. 'start')
  37.  
  38.     test "$IF_PORT" && /sbin/ifport $DEVICE $IF_PORT
  39.  
  40.     if is_true $BOOTP ; then
  41.     /sbin/ifconfig $DEVICE up 0.0.0.0
  42.     /sbin/route add default dev $DEVICE
  43.     eval `/sbin/bootpc --bootfile '' --returniffail \
  44.         --timeoutwait 10 --dev $DEVICE`
  45.     /sbin/route del default
  46.     /sbin/ifconfig $DEVICE down
  47.     if [ "$GATEWAYS" ] ; then
  48.         set - $GATEWAYS ; GATEWAY=$1
  49.     fi
  50.     fi
  51.  
  52.     if is_true $DHCP ; then
  53.     /sbin/ifconfig $DEVICE up 0.0.0.0
  54.     /sbin/route add default dev $DEVICE
  55.     L=/var/run/dhcp-lock-$DEVICE
  56.     /bin/echo "#!/bin/sh\nrm $L" > $L ; chmod +x $L
  57.     /sbin/dhcpcd -c $L $DEVICE
  58.     for t in 0 1 2 3 4 5 6 7 8 9 ; do
  59.         sleep 2 ; if [ -e $L ] ; then break ; fi
  60.     done
  61.     rm -f $L
  62.     if [ -e /etc/dhcpc/resolv.conf ] ; then
  63.         echo "# $DEVICE begin" > $RESOLV.N
  64.         cat /etc/dhcpc/resolv.conf >> $RESOLV.N
  65.         echo "# $DEVICE end" >> $RESOLV.N
  66.         cat $RESOLV >> $RESOLV.N ; mv $RESOLV.N $RESOLV
  67.     fi
  68.     fi
  69.     
  70.     if [ "$IPADDR" ] ; then
  71.  
  72.     # Basic network setup
  73.     BC=${BROADCAST:+broadcast $BROADCAST}
  74.     /sbin/ifconfig $DEVICE up $IPADDR netmask $NETMASK $BC
  75.  
  76.     if [ "$NETWORK" ] ; then
  77.         /sbin/ifuser $DEVICE $NETWORK || \
  78.         /sbin/route add -net $NETWORK netmask $NETMASK dev $DEVICE
  79.     elif [ "$GATEWAY" ] ; then
  80.         /sbin/ifuser $DEVICE $GATEWAY || \
  81.         /sbin/route add $GATEWAY $DEVICE
  82.     fi
  83.  
  84.     test "$GATEWAY" && /sbin/route add default gw $GATEWAY metric 1
  85.  
  86.     # Update DNS stuff
  87.     if [ "$DOMAIN$SEARCH$DNSSRVS$DNS_1$DNS_2$DNS_3" ] ; then
  88.         echo "# $DEVICE begin" > $RESOLV.N
  89.         test "$DOMAIN" && echo "domain $DOMAIN" >> $RESOLV.N
  90.         test "$SEARCH" && echo "search $SEARCH" >> $RESOLV.N
  91.         for DNS in $DNSSRVS $DNS_1 $DNS_2 $DNS_3 ; do
  92.         echo "nameserver $DNS" >> $RESOLV.N
  93.         done
  94.         echo "# $DEVICE end" >> $RESOLV.N
  95.         cat $RESOLV >> $RESOLV.N
  96.         mv $RESOLV.N $RESOLV
  97.     fi
  98.  
  99.     # Handle NFS mounts
  100.     if [ "$MOUNTS" ] ; then
  101.         for MT in $MOUNTS ; do mount -v $MT ; done
  102.     fi
  103.  
  104.     fi
  105.  
  106.     if [ "$IPX_NETNUM" ] ; then
  107.     ipx_interface add $DEVICE $IPX_FRAME $IPX_NETNUM
  108.     fi
  109.  
  110.     start_fn $DEVICE
  111.     ;;
  112.  
  113. 'stop')
  114.  
  115.     stop_fn $DEVICE
  116.     
  117.     if is_true $BOOTP || is_true $DHCP || [ "$IPADDR" ] ; then
  118.  
  119.     # Shut down all NFS mounts on this interface
  120.     nfsstop ()
  121.     {
  122.         while read HOST MT ; do
  123.         if /sbin/ifuser $DEVICE $HOST ; then
  124.             fuser -s -k -m $MT
  125.             umount -v $MT
  126.         fi
  127.         done
  128.     }
  129.     mount -t nfs | sed -e 's/:.* on \(.*\) type .*/ \1/' | nfsstop
  130.  
  131.     test "$IPX_NETNUM" && ipx_interface del $DEVICE $IPX_FRAME
  132.  
  133.     # Remove nameservers
  134.     if fgrep -q "# $DEVICE begin" $RESOLV ; then
  135.         sed -e "/# $DEVICE begin/,/# $DEVICE end/d"    \
  136.         < $RESOLV > $RESOLV.N
  137.         mv $RESOLV.N $RESOLV
  138.     fi
  139.  
  140.     if is_true $DHCP ; then
  141.         kill -TERM `cat /var/run/dhcpcd-$DEVICE.pid`
  142.         rm -f /var/run/dhcpcd-$DEVICE.pid
  143.     fi
  144.     fi
  145.     /sbin/ifconfig $DEVICE down
  146.     ;;
  147.  
  148. 'check')
  149.     /sbin/ifconfig $DEVICE | grep -q RUNNING || exit 0
  150.  
  151.     # Check for any in-use NFS mounts
  152.     nfscheck ()
  153.     {
  154.     while read HOST MT ; do
  155.         /sbin/ifuser $DEVICE $HOST && fuser -sm $MT && exit 1
  156.     done
  157.     }
  158.     mount -t nfs | sed -e 's/:.* on \(.*\) type .*/ \1/' | nfscheck
  159.  
  160.     # Check for active TCP or UDP connections
  161.     getdests ()
  162.     {
  163.         IFS=" :" ; read A ; read A
  164.     while read A B C D E HOST PORT STATE ; do
  165.         if [ "$STATE" != "FIN_WAIT1" -a "$STATE" != "FIN_WAIT2" \
  166.         -a "$STATE" != "CLOSE_WAIT" -a "$STATE" != "TIME_WAIT" \
  167.         -a "$HOST" != "127.0.0.1" -a "$HOST" != "0.0.0.0" \
  168.         -a "$PORT" != "*" ] ; then
  169.         echo $HOST
  170.         fi
  171.     done
  172.     }
  173.     DESTS=`netstat -ntuw | getdests`
  174.     /sbin/ifuser $DEVICE $DESTS && exit 1
  175.     ;;
  176.  
  177. 'cksum')
  178.     chk_simple "$3,$SOCKET,$INSTANCE,$HWADDR" || exit 1
  179.     ;;
  180.  
  181. 'restart')
  182.     test "$IPADDR" && /sbin/ifconfig $DEVICE down up
  183.     ;;
  184.  
  185. 'suspend'|'resume')
  186.     ;;
  187.  
  188. *)
  189.     usage
  190.     ;;
  191.  
  192. esac
  193.  
  194. exit 0
  195.